import { boot } from 'quasar/wrappers'
import { setCssVar } from 'quasar'
// import 'default-passive-events'
import Store from 'src/store'

// Be careful when using SSR for cross-request state pollution
// due to creating a Singleton instance here;
// If any client changes this (global) instance, it might be a
// good idea to move this instance creation inside of the
// "export default () => {}" function below (which runs individually
// for each client)
const themeColor = JSON.parse(localStorage.getItem('themeColor_GFYW'))

if (themeColor && themeColor.primary) {
    setCssVar('primary', themeColor.primary)
    setCssVar('secondary', themeColor.secondary)
    setCssVar('accent', themeColor.accent)
} else {
    setCssVar('primary', '#009900')
    setCssVar('secondary', '#FE6D01')
    setCssVar('accent', '#FFCD07')

    Store.commit('theme/SET_THEME_COLOR', {
        primary: '#009900',
        accent: '#FFCD07',
        secondary: '#FE6D01'
    })
}

export default boot(({ app }) => {
    app.config.globalProperties.themeColor = themeColor;
})

export { themeColor }